﻿namespace DomainServices.Tools.SourceLocation
{
    using DomainServices.Tools.SharedTypes;
    using System;
    using System.Reflection;

    internal class SourceInfoSourceFileProviderFactory : ISourceFileProviderFactory
    {
        public ISourceFileProvider CreateProvider()
        {
            return new SourceInfoSourceFileProvider();
        }

        internal class SourceInfoSourceFileProvider : ISourceFileProvider, IDisposable
        {
            public void Dispose()
            {
            }

            public string GetFileForMember(MemberInfo memberInfo)
            {
                SourceInfo sourceInfoFromAttributes = SourceInfo.GetSourceInfoFromAttributes(memberInfo.GetCustomAttributes(false));
                if (sourceInfoFromAttributes != null)
                {
                    return sourceInfoFromAttributes.FileName;
                }
                return null;
            }
        }
    }
}

